# Maintainer: Bruno Pagani <archange@archlinux.org>
# Contributor: Timothy Redaelli <timothy.redaelli@gmail.com>
# Contributor: Cedric Girard <girard.cedric@gmail.com>
# Contributor: foxbunny <bg.branko@gmail.com>

_pkgname=DisplayCAL
pkgname=displaycal
pkgver=3.9.10
pkgrel=2
pkgdesc="Open Source Display Calibration and Characterization powered by Argyll CMS (Formerly known as dispcalGUI)"
arch=(loong64 x86_64)
url="https://github.com/eoyilmaz/displaycal-py3"
license=(GPL3)
depends=(argyllcms dbus dbus-python glib2 python-certifi python-distro
         python-numpy python-pillow python-send2trash python-wxpython
         python-zeroconf)
makedepends=(libxrandr libxxf86vm python-build python-installer
             python-setuptools python-wheel)
optdepends=('gnome-color-manager: profile installation for GNOME'
            'colord-kde: profile installation for KDE Plasma')
source=(${url}/releases/download/${pkgver}/${_pkgname}-${pkgver}.tar.gz
        3762e7be.patch)
sha256sums=('a031c355bd33b800b8f723df98d7bbc6e14a680d414591abef95f0b0baae807b'
            'a392f409342e7eb7892f0341c550fd26a8a8e65672ed1f039adbf6f524ebd701')

prepare() {
  cd ${_pkgname}-${pkgver}
  patch -p1 -i ../3762e7be.patch # Fix build with Python 3.11
}

build() {
  cd ${_pkgname}-${pkgver}
  python -m build --wheel --no-isolation
}

package() {
  cd ${_pkgname}-${pkgver}
  python -m installer --destdir="${pkgdir}" dist/*.whl
  # https://github.com/eoyilmaz/displaycal-py3/issues/117
  install -d "${pkgdir}"/etc/xdg/autostart
  local site_packages=$(python -c "import site; print(site.getsitepackages()[0])")
  mv "${pkgdir}"/{$site_packages/build/.config,etc/xdg}/autostart/z-displaycal-apply-profiles.desktop
  rmdir "${pkgdir}"/$site_packages/build/{.config{/autostart,},}
}
